using System;
using System.Timers; 
using Core;
using System.Collections.Generic;
using MongoDBHelper;
using System.Configuration;

namespace MonoAgent
{
	public class MonoAgentService
	{
    	readonly Timer _timer;
		
    	public MonoAgentService()
		{
        	_timer = new Timer(1000) {AutoReset = true};
        	_timer.Elapsed += InsertLogs;
    	}
    	public void Start() { _timer.Start(); }
    	public void Stop() { _timer.Stop(); }
		
		public void InsertLogs(object sender, EventArgs eventArgs)

		{
			Context context1 = new Context("Key1","Value1");
			Context context2 = new Context("Key2","Value2");
			List<Context> contextlist = new List<Context>() ;
			contextlist.Add(context1);
			contextlist.Add(context2);
			
			ApplicationEvent appEvent = new ApplicationEvent("FirstEvent","Value",DateTime.Now.ToString(),contextlist);
			ApplicationEvent appEvent1 = new ApplicationEvent("Event2","Value2",DateTime.Now.AddSeconds(20).ToString(),contextlist);
			
			List<ApplicationEvent> appEventList = new List<ApplicationEvent>();
			appEventList.Add(appEvent);
			appEventList.Add(appEvent1);
			
			MongoDBAPI db = new MongoDBAPI(ConfigurationSettings.AppSettings["ServerName"],
			                                              ConfigurationSettings.AppSettings["DatabaseName"]);                      			
			
			db.SaveLogs(appEventList);
			db.SaveLogsPerSecond(appEventList);			
		}
	}
}

